﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/InternalPage.Master" Inherits="MvcContrib.FluentHtml.ModelViewPage<RegistrationViewModel>" %>

<asp:Content ID="registerTitle" ContentPlaceHolderID="TitleContent" runat="server">
  Register
</asp:Content>
<asp:Content ID="registerPlaceholder" ContentPlaceHolderID="PageHeader" runat="server">
  Create a New Account</asp:Content>
<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">
  <p>
    Passwords are required to be a minimum of
    <%=Html.Encode(ViewData["PasswordLength"])%>
    characters in length.
  </p>
  <div class="account-form">
    <% Html.BeginForm("Register", "Registration", FormMethod.Post, new { id = "registrationForm" }); %>
    <div class="center">
      <span class="logon-header">Register with Give-A-Quiz.com</span></div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.UserName).Value("Username:") %>
      <%= this.TextBox(m => m.UserName).Class("text").ValidateForRequired() %>
    </div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.FirstName).Value("First Name:") %>
      <%= this.TextBox(m => m.FirstName).Class("text").ValidateForRequired() %>
    </div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.LastName).Value("Last Name:") %>
      <%= this.TextBox(m => m.LastName).Class("text").ValidateForRequired() %>
    </div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.Email).Value("Email:") %>
      <%= this.TextBox(m => m.Email)
            .Class("text")
            .ValidateForRequired() 
            .ValidateForEmail() %>
    </div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.Password).Value("Password:") %>
      <%= this.Password(m => m.Password)
            .Class("text")
            .ValidateForRequired()
            .ValidateForMinLength(Convert.ToInt32(ViewData["PasswordLength"])) %>
    </div>
    <div class="clearDiv entry-row">
      <%= this.Label(m => m.RepeatPassword).Value("Repeat Password:") %>
      <%= this.Password(m => m.RepeatPassword)
            .Class("text")
            .ValidateForRequired()
            .ValidateForMinLength(Convert.ToInt32(ViewData["PasswordLength"])) %>
    </div>
    <div class="center">
      <a href="#" onclick="javascript:submitRegistrationForm()" class="btn">Register</a>
    </div>
    <% Html.EndForm(); %>
  </div>
</asp:Content>
<asp:Content ID="registerScripts" ContentPlaceHolderID="Scripts" runat="server">
  <script type="text/javascript">
    var isButtonPressed = false;
    $(document).ready(function () {
      $('#registrationForm').validate({
        // need to explicitly set this option - other rules are set by html meta-data
        rules: { RepeatPassword: { equalTo: "#registrationForm #Password"} }
      }); // jquery validation 
      // don't let the enter key trigger form submission
      $('#registrationForm').submit(function () {
        if (!isButtonPressed) { return false; }
      });
    });

    function submitRegistrationForm() {
      isButtonPressed = true;
      $('#registrationForm').trigger('submit'); // submit the form
      return false; //return false to stop the link from doing anything
    }
  </script>
</asp:Content>
